package com.wangxinyuchuan.demo.singleton;

/**
 * @author wangxinyuchuan
 * @date 2023/4/14 12:24 PM
 */
public class TicketMarker {

    private int ticket = 1000;

    private static TicketMarker singleton = new TicketMarker();

    // 防止多线程下返回相同的编号
    public synchronized int getNextTicketNumber() {
        return ticket++;
    }

    public static TicketMarker getInstance() {
        return singleton;
    }


    public static void main(String[] args) {
        for (int i = 0; i <= 100; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "---->" + TicketMarker.getInstance().getNextTicketNumber());
            }).start();
        }
    }
}
